Page({
  data: {
    appointmentList: [], // 预约列表
    loading: true // 是否正在加载
  },

  onLoad() {
    this.loadAppointments();
  },

  // 加载预约列表
  loadAppointments() {
    const that = this;
    wx.request({
      url: 'https://your-api-endpoint.com/appointments', // 替换为你的API接口地址
      method: 'GET',
      success(res) {
        if (res.statusCode === 200) {
          that.setData({
            appointmentList: res.data.appointments || [],
            loading: false
          });
        } else {
          wx.showToast({
            title: '加载失败，请重试',
            icon: 'none'
          });
        }
      },
      fail() {
        wx.showToast({
          title: '网络错误',
          icon: 'none'
        });
      }
    });
  },

  // 确认预约
  confirmAppointment(e) {
    const appointmentId = e.currentTarget.dataset.id;
    const that = this;

    wx.request({
      url: `https://your-api-endpoint.com/appointments/${appointmentId}/confirm`, // 替换为你的API接口地址
      method: 'POST',
      success(res) {
        if (res.statusCode === 200) {
          wx.showToast({
            title: '预约确认成功',
            icon: 'success'
          });
          // 刷新预约列表
          that.loadAppointments();
        } else {
          wx.showToast({
            title: '确认失败，请重试',
            icon: 'none'
          });
        }
      },
      fail() {
        wx.showToast({
          title: '网络错误',
          icon: 'none'
        });
      }
    });
  }
});